      SUBROUTINE DNSMAG(ISKEL,DEP,SMAGB,SMAGM)
C
      IMPLICIT REAL*8(A-H,O-Z)
C
      COMMON/IPOOL1/IGRAV,IDAMP,IK,K1,ITIM,IDUM1(34)
C
      COMMON/RPOOL1/RHOK(10),TIME,SA(3,3),FM1(3,3),ZLK(10),DUM01(86)
C
      COMMON/RPOOL5/CKMAT(3,3,10),FM2(3,3)
C
      COMMON/DNSWRK/NSELB,NSELT,IASEL,IBSEL,ICSEL,LOC
C
      COMMON/TMSINR/TIPINR(3,10),RSQ(3,10),XIPL(6),BETL(6)
C
C
      DIMENSION DEP(150),SMAGB(3),SMAGM(3)
      DIMENSION SMAT(3,3),FCM(3,3),DM1(3,3),DM2(3,3)
C
C
      IFLAG=NSELB+NSELT
      IF(IFLAG.NE.0) GO TO 10
      DO 5 I=1,3
      SMAGM(I)=SMAGB(I)
    5 CONTINUE
C
      RETURN
C
   10 CONTINUE
C
      ZL=ZLK(ISKEL)
      U1P=1.0D0
      U2P=0.0D0
      U3P=0.0D0
      F=0.5D0
      W22=0.0D0
      W33=0.0D0
C
      IF(NSELB.EQ.0) GO TO 35
      IA=IASEL-1
      IB=IBSEL-1
      DO 20 I=1,NSELB
      I1=IA+I
      I2=IB+I
      I3=LOC+I
      WS=XIPL(I3)/ZL
      U2P=U2P+DEP(I1)*WS
      U3P=U3P+DEP(I2)*WS
   20 CONTINUE
      W22=U2P*U2P
      W33=U3P*U3P
      U1P=1.0D0-W22-W33
      IF(U1P.LT.0.0D0) U1P=0.0D0
      U1P=DSQRT(U1P)
      F=1.0D0/(1.0D0+U1P)
C
   35 CONTINUE
C
      TWI=0.0D0
      ST=0.0D0
      CT=1.0D0
C
      IF(NSELT.EQ.0) GO TO 45
C
      IC=ICSEL-1
      DO 40 I=1,NSELT
      I1=IC+I
      I2=LOC+I
      TWI=TWI+DEP(I1)*BETL(I2)
   40 CONTINUE
      ST=DSIN(TWI)
      CT=DCOS(TWI)
C
   45 CONTINUE
C
      SMAT(1,1)=U1P
      SMAT(1,2)=U2P
      SMAT(1,3)=U3P
      SMAT(2,1)=-U3P*ST-U2P*CT
      SMAT(3,1)=U2P*ST-U3P*CT
      WS1=U2P*U3P*F
      WS2=1.0D0-W22*F
      WS3=1.0D0-W33*F
      SMAT(2,2)=-WS1*ST+WS2*CT
      SMAT(3,2)=-WS2*ST-WS1*CT
      SMAT(2,3)=WS3*ST-WS1*CT
      SMAT(3,3)=WS1*ST+WS3*CT
C
      IF(ISKEL.GT.K1) GO TO 46
      CALL MPYMAT(FM1,CKMAT(1,1,ISKEL),DM1,1,1,FCM,DM1)
      GO TO 47
C
   46 CONTINUE
C
      CALL MPYMAT(FM2,CKMAT(1,1,ISKEL),DM1,1,1,FCM,DM1)
C
   47 CONTINUE
C
      CALL MPYMAT(FCM,SMAT,FCM,2,2,DM1,DM2)
      CALL MATV(1,DM2,SMAGB,SMAGM)
C
C
      RETURN
C
C
      END
